package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目模块功能
 * @Author 孔德强
 * @Since 2025-1-10
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目接口")
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 护理模块的分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    public ResponseResult<PageResponse<List<NursingProjectVo>>> queryPage(String name, Integer pageNum, Integer pageSize, Integer status){
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.queryPage(name,pageNum,pageSize,status);
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    //编辑功能的回写
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询房型")
    public ResponseResult<NursingProjectVo> findNursingProjectById(@PathVariable Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    //数据的更新
    @PutMapping
    @ApiOperation("更新护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult OnOrNot(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        nursingProjectService.OnOrNot(id,status);
        return success();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable("id") Long id){
        nursingProjectService.delete(id);
        return success();
    }

    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>> getAll(){
        List<NursingProjectVo> nursingProjectAll = nursingProjectService.getAll();
        return success(nursingProjectAll);
    }
    /**
     * springmvc 的传参方式
     *
     * restful ----GetMapping
     * 1.get 普通类型传参
     * http://localhost/user?name='a'&age='2' -----queryPage(String name,@RequestParam("age") Integer nianlin)
     * 2.get 普通对象类型传参
     * http://localhost/user?name='aa'&age='2' -------queryPage(User user)
     * 3.post json 请求体传参
     * http://localhost/user --------------------queryPage(@RequestBody User user)
     * 4.restful 风格 路径传参
     * http://localhost/user/zhangsan/20 -----------@GetMapping(/user/{name}/{age}) --->queryPage(@Pathvariable("name")String name,@Pathvariable("age") Integer age)
     */
}





















